Imports System.IO

Public Class clsGnrtFile

  Private Sub mprCreateFolder(ByVal aStrFolderName As String)

    If Directory.Exists("C:\" & aStrFolderName) = False Then

      Directory.CreateDirectory("C:\" & aStrFolderName)

    End If

  End Sub





  Public Function mprGnrtDesignerFile _
                                      (ByVal aStrFileText As String _
                                     , ByVal aStrFileName As String _
                                     , ByVal aStrFolderName As String)

    mprCreateFolder(aStrFolderName)

    Dim lObjFileStream As New FileStream _
                    ("C:\" & aStrFolderName & "\" & aStrFileName & ".Designer.vb" _
                    , FileMode.Create _
                    , FileAccess.Write)
    Dim lObjStreamWriter As New StreamWriter(lObjFileStream)
    lObjStreamWriter.BaseStream.Seek(0, SeekOrigin.End)
    lObjStreamWriter.WriteLine(aStrFileText)
    lObjStreamWriter.Close()

    Return True

  End Function





  Public Sub mprGnrtHelperFile(ByVal aStrFileText As String _
                                                         , ByVal aStrFileName As String _
                                                         , ByVal aStrFolderName As String)

    mprCreateFolder(aStrFolderName)

    Dim lObjFileStream As New FileStream _
                                               ("C:\" & aStrFolderName & "\" & aStrFileName & ".Helper.vb" _
                                               , FileMode.Create _
                                               , FileAccess.Write)
    Dim lObjStreamWriter As New StreamWriter(lObjFileStream)

    lObjStreamWriter.BaseStream.Seek(0, SeekOrigin.End)
    lObjStreamWriter.WriteLine(aStrFileText)
    lObjStreamWriter.Close()

  End Sub




  Public Sub mprGnrtVbFiles(ByVal aStrFile_Text As String _
                                                   , ByVal aStrFile_Name As String _
                                                   , ByVal aStrFolderName As String)

    mprCreateFolder(aStrFolderName)

    Dim mfile_strm As New FileStream _
                      ("C:\" & aStrFolderName & "\" & aStrFile_Name & ".vb" _
                      , FileMode.Create _
                      , FileAccess.Write)
    Dim sStr As New StreamWriter(mfile_strm)

    sStr.BaseStream.Seek(0, SeekOrigin.End)
    sStr.WriteLine(aStrFile_Text)
    sStr.Close()

  End Sub





  Public Sub mprGnrtProCHedrFile _
                            (ByVal aStrFile_Text As String _
                           , ByVal aStrFile_Name As String _
                           , ByVal aStrFolderName As String)

    mprCreateFolder(aStrFolderName & "\" & "Pro C Header")

    Dim mfile_strm As New FileStream _
                    ("C:\" & aStrFolderName & "\" & "Pro C Header" & "\" & aStrFile_Name & ".h" _
                    , FileMode.Create _
                    , FileAccess.Write)
    Dim sStr As New StreamWriter(mfile_strm)

    sStr.BaseStream.Seek(0, SeekOrigin.End)
    sStr.WriteLine(aStrFile_Text)
    sStr.Close()

  End Sub






  Public Sub mprGnrtProCBodyFile _
                            (ByVal aStrFile_Text As String _
                           , ByVal aStrFile_Name As String _
                           , ByVal aStrFolderName As String)

    mprCreateFolder(aStrFolderName & "\" & "Pro C Body")

    Dim mfile_strm As New FileStream _
                    ("C:\" & aStrFolderName & "\" & "Pro C Body" & "\" & aStrFile_Name & ".pc" _
                    , FileMode.Create _
                    , FileAccess.Write)
    Dim sStr As New StreamWriter(mfile_strm)

    sStr.BaseStream.Seek(0, SeekOrigin.End)
    sStr.WriteLine(aStrFile_Text)
    sStr.Close()

  End Sub




  Public Sub mPrGnrtDbScriptFile _
                             (ByVal aStrFileText As String _
                             , ByVal aStrFileName As String _
                             , ByVal aStrFolderName As String)


    Dim lFileStream As FileStream
    Dim lStreamWriter As StreamWriter

    mprCreateFolder(aStrFolderName)

    If File.Exists("C:\" & aStrFolderName & "\" & aStrFileName) = False Then
      lFileStream = New FileStream _
                                        ("C:\" & aStrFolderName & "\" & aStrFileName & ".sql" _
                                        , FileMode.Create _
                                        , FileAccess.Write)

      lStreamWriter = New StreamWriter(lFileStream)
      lStreamWriter.BaseStream.Seek(0, SeekOrigin.End)
      lStreamWriter.WriteLine(aStrFileText)
      lStreamWriter.Close()
    End If

  End Sub

End Class
